﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using Extensions.Windows;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ExtensionsTests
{
    /// <summary>
    /// Contains all <see cref="IFrameworkElement"/> tests
    /// </summary>
    [TestClass]
    public class IFrameworkElementTests
    {
        [TestMethod]
        public void AsFrameworkElement_SuccessfullyTypesFrameworkElement()
        {
            var button = new Button();

            IFrameworkElement typed = button.AsFrameworkElement();
            Assert.IsNotNull( typed );
        }

        [TestMethod]
        public void AsFrameworkElement_SuccessfullyTypesFrameworkContentElement()
        {
            var run = new Run();

            IFrameworkElement typed = run.AsFrameworkElement();
            Assert.IsNotNull( typed );
        }

        [TestMethod]
        public void AsFrameworkElement_ReturnsNullForElementsThatAreNotFrameworkElementOrFrameworkContentElement()
        {
            var dependencyObject = new DependencyObject();

            IFrameworkElement typed = dependencyObject.AsFrameworkElement();
            Assert.IsNull( typed );
        }

        [TestMethod]
        public void AsFrameworkElement_DataContextRemainsTheSame()
        {
            string dataContext = "DataContext";
            var button = new Button { DataContext = dataContext };

            IFrameworkElement typed = button.AsFrameworkElement();
            Assert.AreSame( dataContext, typed.DataContext );
        }
    }
}